cmake_minimum_required(VERSION 3.14)

project(WLRobotics LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找依赖库
find_package(Boost REQUIRED COMPONENTS system thread)
find_package(lcm REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
find_package(OpenCV REQUIRED)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

# 包含 ROS 头文件路径
include_directories(${catkin_INCLUDE_DIRS})

# 添加自定义头文件路径
set(INCLUDE_DIR_JSON ${CMAKE_CURRENT_SOURCE_DIR}/include/json)
set(INCLUDE_DIR_SPDLOG ${CMAKE_CURRENT_SOURCE_DIR}/include/spdlog)
set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/siyi/sdk)
include_directories(
  ${INCLUDE_DIR_JSON}
  ${INCLUDE_DIR_SPDLOG}
  ${SDK_DIR}
)

# 查找并包含所有源文件
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
file(GLOB_RECURSE SRC_FILES
  ${SRC_DIR}/log/*.h
  ${SRC_DIR}/log/*.cpp
  ${SRC_DIR}/config/*.h
  ${SRC_DIR}/config/*.cpp
  ${SRC_DIR}/app/*.h
  ${SRC_DIR}/app/*.cpp
  ${SRC_DIR}/common/*.h
  ${SRC_DIR}/common/*.cpp
  ${SRC_DIR}/collection/*.h
  ${SRC_DIR}/collection/*.cpp
  ${SRC_DIR}/sigcontrol/*.hpp
  ${SRC_DIR}/sigcontrol/*.cpp
  ${SRC_DIR}/sigcontrol/*.h
  ${SRC_DIR}/util/*.cpp
  ${SRC_DIR}/util/*.h
  ${SRC_DIR}/mission/*.h
  ${SRC_DIR}/mission/*.cpp
  ${SRC_DIR}/collection/channel/*.hpp
  ${SRC_DIR}/collection/channel/*.h
  ${SRC_DIR}/siyi/*.hpp
  ${SRC_DIR}/siyi/*.cpp
)

# 设置可执行文件目标
add_executable(WLRobotics
  main.cpp
  ${SRC_FILES}
)

# 查找并链接pthread库
find_package(Threads REQUIRED)

# 查找并链接JSON库和SPDLOG库
set(JSON_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/lib/json/libjsoncpp.a)
set(SPDLOG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/lib/spdlog/libspdlog.a)

# 链接目标与依赖库
target_link_libraries(WLRobotics
  ${JSON_LIBRARY}
  ${SPDLOG_LIBRARY}
  ${catkin_LIBRARIES}  # 链接 ROS 库
  ${Boost_LIBRARIES}
  lcm
  ${LCM_LIBRARIES}
  ${OpenCV_LIBS}
  OpenSSL::SSL
  OpenSSL::Crypto
  CURL::libcurl
  ${CMAKE_THREAD_LIBS_INIT}
  stdc++fs
)

# 设置可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/wlr)

# 复制CFG目录到输出路径
file(COPY ${PROJECT_SOURCE_DIR}/CFG DESTINATION ${EXECUTABLE_OUTPUT_PATH})
